package com.example.multitenancy01.controller;

import com.example.multitenancy01.config.MyContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *  上下文 控制器
 */

@RestController
@RequestMapping("/myContextController")
public class MyContextController {

    @Autowired
    private MyContext apiContext;

    /**
     *  127.0.0.1:8080/myContextController/setCurrentTenantId?number=2
     *   在上下文中设置当前多租户id
     *   登录的时候，再来赋值，用来区分多租户
     */
    @RequestMapping("/setCurrentTenantId")
    public void setCurrentTenantId(@RequestParam int number){
        apiContext.setCurrentTenantId((long)number);
    }
}
